//
//  LLAccountViewController.m
//  LoveLove
//
//  Created by 达迩科技 on 2019/4/9.
//  Copyright © 2019 wkf. All rights reserved.
//

#import "LLAccountViewController.h"
#import "LLPayView.h"
#import "LLboughtContentViewController.h"
#import "LLTransactionRecordsViewController.h"

@interface LLAccountViewController ()<UINavigationControllerDelegate,LLPayViewDelete>
@property (copy, nonatomic) NSArray *titleArray;
@property (strong, nonatomic) LLPayView *payView;
@end

@implementation LLAccountViewController

- (void)viewWillAppear:(BOOL)animated {
    [[IQKeyboardManager sharedManager] setEnable:NO];
    [super viewWillAppear:animated];
    [SVProgressHUD dismiss];
    self.navigationController.delegate = self;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    //TODO: 页面Disappear 启用
    [[IQKeyboardManager sharedManager] setEnable:YES];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.titleArray = @[@"已购内容",@"交易记录"];
    [self titleView];
    self.titleLabel.text = @"账户";
    self.rightButton.hidden = YES;
    
    self.navigationController.navigationBar.barTintColor = LLWhiteColor;
    // Do any additional setup after loading the view.
}

#pragma mark - 显示视图操作方法
- (void)configTableView {
    self.needRefresh = NO;
    [super configTableView];
    self.tableView.top = self.navH;
    self.tableView.mj_h = LLScreenHeight-self.navH;
    self.tableView.backgroundColor = LLColorRGB(255);
    [self.tableView registerCellByClassName:@"UITableViewCell"];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    } else {
        return self.titleArray.count;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;//无高亮选中
        cell.backgroundColor = [UIColor whiteColor];
        
        UILabel *walletLabel = [LLInitBaseViewTool labelWithText:@"88.88" textColor:LLColorRGB(0) font:29 textAlignment:NSTextAlignmentCenter];
        walletLabel.frame = CGRectMake(0, 56, LLScreenWidth, 29);
        [cell addSubview:walletLabel];
        
        LLButton *button = [LLInitBaseViewTool buttonWithTitle:@"充 值" image:nil titleColor:LLWhiteColor font:17];
        [button setBackgroundImage:[UIImage imageNamed:@"底 拷贝 3"] forState:0];
        button.frame = CGRectMake(38, 128, LLScreenWidth-76, 50);
        [button addTarget:self action:@selector(didPAyto) forControlEvents:UIControlEventTouchUpInside];
        [cell addSubview:button];
        return cell;
    } else {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;//无高亮选中
        cell.backgroundColor = [UIColor whiteColor];
        cell.textLabel.textColor = LLColorRGB(11);
        cell.textLabel.text = self.titleArray[indexPath.row];
        cell.textLabel.font = LLRegularFont(15);
        return cell;
    }
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 1) {
        return 45;
    } else {
        return 222;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.0000001;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.0000001;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return nil;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return nil;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.section == 1) {
        if (indexPath.row == 0) {
            LLboughtContentViewController *vc = [LLboughtContentViewController new];
            [self.navigationController pushViewController:vc animated:YES];
        } else {
            LLTransactionRecordsViewController *vc = [LLTransactionRecordsViewController new];
            [self.navigationController pushViewController:vc animated:YES];
        }
    }
}

#pragma mark - 充值
- (void)didPAyto{
    [self payView];
    _payView.hidden = NO;
}

- (void)didSelectButton:(LLPayView *)view didClickItem:(NSInteger)item{
    _payView.hidden = YES;
}

-(LLPayView *)payView{
    if (_payView == nil) {
        _payView = [[LLPayView alloc] initWithFrame:self.view.bounds];
        _payView.hidden = YES;
        _payView.delegate = self;
        [self.view addSubview:_payView];
    }
    return _payView;
}
#pragma mark - UINavigationControllerDelegate
// 将要显示控制器
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    // 判断要显示的控制器是否是自己
    BOOL isShowHomePage = [viewController isKindOfClass:[self class]];
    [self.navigationController setNavigationBarHidden:isShowHomePage animated:YES];
}

- (void)dealloc {
    self.navigationController.delegate = nil;
    [LLNotificationCenter removeObserver:self];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
